package com.doge.walknovel.widgets

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.doge.wnpro.R
import com.doge.wnpro.databinding.LayoutAppToolbarBinding
import com.doge.walknovel.utils.activity
import com.doge.walknovel.utils.setOnClickCallback

class AppToolbar @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null
) : LinearLayout(context, attrs) {
    val binding =
        LayoutAppToolbarBinding.inflate(LayoutInflater.from(context), this)

    init {
        orientation = VERTICAL
        if (attrs != null) {
            val a = context.obtainStyledAttributes(attrs, R.styleable.AppToolbar, 0, 0)
            val title = a.getText(R.styleable.AppToolbar_title)
            binding.pageTitle.text = title
            a.recycle()
        }
        binding.pageBack.setOnClickCallback {
            activity?.onBackPressed()
        }
    }
}